package my.action.author;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import my.controller.Action;
import my.controller.ActionForward;
import my.db.DAO.ArticleDAO;
import my.db.DAO.AuthorDAO;
import my.db.DTO.ArticleDTO;
import my.db.DTO.AuthorDTO;

public class getAuthorAction implements Action{

	@Override
	public ActionForward execute(HttpServletRequest request,HttpServletResponse response) throws Exception {
		
		//Fields
		AuthorDAO adao=new AuthorDAO();
		ArticleDAO ardao=new ArticleDAO();
		String r=(String)request.getParameter("authordetailid");
		AuthorDTO adto=adao.getAuthor(Integer.parseInt(r));
		ActionForward forward=new ActionForward();
		ArrayList<ArticleDTO> lst_ar=ardao.getArticleAuthor(Integer.parseInt(r));
		
		//Checking condition
		if(lst_ar !=null){
			request.setAttribute("authordetailArticle", lst_ar);
			request.setAttribute("authordetail",adto);
			forward.setPath("./author_detail.jsp");
			forward.setRedirect(false);
		}	
		return forward;
	}

}
